package com.eatme.web.validation;

import com.eatme.web.security.domain.vo.UserRequest;
import com.eatme.web.validation.annotation.PasswordMatches;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class PasswordMatchesValidator implements ConstraintValidator<PasswordMatches, UserRequest> {

    @Override
    public void initialize(final PasswordMatches constraintAnnotation) { }

    @Override
    public boolean isValid(final UserRequest obj, final ConstraintValidatorContext context) {
        UserRequest user = (UserRequest) obj;
        return user.getPassword().equals(user.getMatchingPassword());
    }
}
